package vip.specimen.system.datasource.validation.implement;

import vip.specimen.system.datasource.entity.SystemArticleCategoriesEntity;
import vip.specimen.system.datasource.validation.annotation.CategoriesUnique;
import vip.specimen.system.service.SystemArticleCategoriesService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/8 8:45
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class CategoriesUniqueImp implements ConstraintValidator<CategoriesUnique, String> {
    @Resource
    private SystemArticleCategoriesService articleCategoriesService;
    @Resource
    private HttpServletRequest request;

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        SystemArticleCategoriesEntity categoriesEntity = this.articleCategoriesService.findByCategoriesName(s);
        return null == categoriesEntity || categoriesEntity.getUuid().toString().equals(request.getParameter("uuid"));
    }
}
